<template>
  <div>

    <el-card class="box-card">
      <el-row :gutter="8"
              type="flex"
              align="middle">
        <el-col :span="1.5">
          用户ID
        </el-col>
        <el-col :span="3">
          <el-input size="small"
                    v-model="queryParams.userId"
                    placeholder="请输入用户ID"></el-input>
        </el-col>
        <el-col :span="
                    1.5">
          <el-button size="mini"
                     type="primary"
                     @click="getData()"
                     icon="el-icon-search">搜索</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button icon='el-icon-refresh'
                     size="mini"
                     @click="reset">重置</el-button>
        </el-col>
      </el-row>

      <el-table :data="tableData"
                v-loading="loading"
                style="width: 100%;margin-top:10px"
                :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                :cell-style="{'text-align':'center'}">
        <el-table-column prop="chatRoomId"
                         label="聊天室id"
                         width="320">
        </el-table-column>
        <el-table-column prop="remark"
                         label="备注"
                         width="100">
        </el-table-column>
        <el-table-column prop="chatRoomNickName"
                         label="聊天室别名"
                         width="100">
        </el-table-column>
        <el-table-column prop="isGroupChat"
                         label="会话类型 ">
        </el-table-column>
        <el-table-column prop="groupChatName"
                         label="群聊名称">
        </el-table-column>
        <el-table-column prop="createTime"
                         label="创建时间">
        </el-table-column>
        <el-table-column prop="userId"
                         label="操作">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit"
                       type="text"
                       @click="updateHandler(scope.row.chatRoomId)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryParams.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryParams.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>

    <div>
      <el-dialog title="聊天内容"
                 v-loading="loading"
                 :visible.sync="dialogVisible"
                 width="60%">
        <el-table :data="chatData"
                  v-loading="loading2"
                  height="400"
                  style="width: 100%"
                  :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                  :cell-style="{'text-align':'center'}">
          <el-table-column prop="txPic"
                           label="url"
                           width="130">
            <template slot-scope="scope">
              <el-image style="width: 60px; height: 60px"
                        :src="scope.row.txPic"
                        :preview-src-list="[scope.row.txPic]">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="nickName"
                           label="用户昵称">
          </el-table-column>
          <el-table-column prop="userId"
                           label="用户ID">
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true"
                           prop="message"
                           label="消息内容">
          </el-table-column>
          <el-table-column prop="messageType"
                           label="标题">
            <template slot-scope="scope">
              <span>{{scope.row.messageType==0?'文字消息':scope.row.messageType==1?'语言消息':scope.row.messageType==2?'图文消息':scope.row.messageType==3?'地图':'视频'}}</span>
            </template>

          </el-table-column>
          <el-table-column prop="reTime"
                           label="消息时间"
                           width="130">
          </el-table-column>

        </el-table>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary"
                     @click="dialogVisible=false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template> 

<script>
export default {
  data() {
    return {
      queryParams: { pageNum: 1, pageSize: 5, userId: null },
      loading: false,
      tableData: [],
      chatData: [],
      dialogVisible: false,
      total: 0,
      loading2: false
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getData()
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getData()
    },
    async getData() {
      this.loading = true
      let { data } = await this.$axios.get('scoketChatRoom/room/list', { params: this.queryParams })
      console.log(data)
      this.tableData = data.rows
      this.total = data.total
      this.loading = false
    },
    reset() {
      this.queryParams = { pageNum: 1, pageSize: 5, userId: null }
    },
    async updateHandler(id) {
      this.loading = true
      let { data } = await this.$axios.get(`scoketChatRoom/meg/list`, { params: { chatRoomId: id } })
      console.log(data)
      this.chatData = data.rows
      this.loading = false
      this.dialogVisible = true
    }
  }
}
</script>
   
<style lang="scss" scoped>
.el-card__body {
  padding: 10px;
  padding-top: 20px;
  .btnList {
    margin-bottom: 8px;
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
  }
  .page {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>